#include "cbb_ph_obj.h"
#include <string.h>

// 协议头指针
static PH_t* pstHead = NULL; 

PH_t*
cbb_ph_register(void* pvFeature, PH_Check_t pfnCheck, PH_Append_t pfnAppend){

    // 输入参数检查
    if(NULL == pfnCheck || NULL == pfnAppend || NULL == pvFeature) return NULL;

    // 分配内存
    PH_t* pstPH = (PH_t*)PH_MALLOC(sizeof(PH_t));
    if(NULL == pstPH) return NULL;

    // 初始化对象
    pstPH->pfnCheck = pfnCheck;
    pstPH->pfnAppend = pfnAppend;
    pstPH->pvFeature = pvFeature;

    // 尾插法
    if(NULL != pstHead) pstPH->pstNext = pstHead;
    pstHead = pstPH;

    // 返回结果 
    return pstPH;
}

PH_RET_t 
cbb_ph_clear_buf(PH_Buf_t* pstBuf){

    // 输入参数检查
    if(NULL == pstBuf) return PH_ERR;

    // 清空缓存区
    memset(pstBuf->pu8Buffer, 0, pstBuf->u32BufferLen);
    pstBuf->u32DataLen = 0;

    // 返回结果 
    return PH_OK;
}
